package com.lmaos.basetools.base;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class SDateUtils {
	
	public static final String DATEPATTERN = "yyyyMMdd";
	public static final String YYYYMMDD="yyyyMMdd";
	public static final String YYYY_MM_DD="yyyy-MM-dd";
	public static final String YYYYMMDDHHMISS="yyyyMMddHHmmss";
	public static final String YYYYMMDDHHMISSS="yyyyMMddHHmmssS";
	public static final String YYYY_MM_DD_HH_MI_SS="yyyy-MM-dd HH:mm:ss";
	public static final String YYYY_MM_DD$HH_MI_SS="yyyy-MM-dd$HH:mm:ss";
	public static final String YYYY_MM_DD_HH_MI_SS_S="yyyy-MM-dd HH:mm:ss S";
	public static final String YYYYMMDD$HHMISS="yyyyMMdd$HHmmss";
	public static final String YYYY_MM_DD$HH_MI_SS$S="yyyy-MM-dd$HH:mm:ss$S";
	public static final String YYYYMMDD$HHMISS$S="yyyyMMdd$HHmmss$S";
	/** yyyy-MM-dd HH:mm:ss */
	public static final SimpleDateFormat F_YYYY_MM_DD_HH_MI_SS = new SimpleDateFormat(YYYY_MM_DD_HH_MI_SS);
	/** yyyyMMddHHmmssS */
	public static final SimpleDateFormat F_YYYYMMDDHHMISSS = new SimpleDateFormat(YYYYMMDDHHMISSS);
	/** yyyyMMddHHmmss */
	public static final SimpleDateFormat F_YYYYMMDDHHMISS = new SimpleDateFormat(YYYYMMDDHHMISS);
	/** yyyy-MM-dd */
	public static final SimpleDateFormat F_YYYY_MM_DD = new SimpleDateFormat(YYYY_MM_DD);
	/** yyyyMMdd */
	public static final SimpleDateFormat F_YYYYMMDD = new SimpleDateFormat(YYYYMMDD);
	
	/** 格式化日期
	 * @param date
	 * @param pattern 选择格式
	 * @return
	 */
	public static final String getDateFormat(Date date , String pattern){
		return new SimpleDateFormat(pattern).format(date);
	}
	public static LMDate getLMDate(Date date ,boolean isFG){
		String formats = getDateFormat(date, isFG?YYYY_MM_DD$HH_MI_SS$S:YYYYMMDD$HHMISS$S);
		String dates[] = formats.split("$");
		return new LMDate(dates[0], dates[1],dates[2]);
	}
	public static String getNowFormat(String pattern){
		return getDateFormat(getNowDate(), pattern);
	}
	/**
	 * @param pattern 	填充格式 例如 yyyy-MM-dd
	 * @param dateFormat 格式的日期 例如 2015-06-33
	 * @return 返回毫秒
	 */
	public static long getTime(String pattern,String dateFormat){
		Date date = getDate(pattern, dateFormat);
		if(date != null){
			return date.getTime();
		}
		return 0;
	}
	/**
	 * @param pattern 	填充格式 例如 yyyy-MM-dd
	 * @param dateFormat 格式的日期 例如 2015-06-33
	 * @return 返回时间对象
	 */
	public static Date getDate(String pattern,String dateFormat){
		try {
			return new SimpleDateFormat(pattern).parse(dateFormat);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}
	public static LMDate getNowLMDate(boolean isFG){
		return getLMDate(getNowDate(), isFG);
	}
	public static Date getNowDate(){
		return new Date(System.currentTimeMillis());
	}
	public static class LMDate{
		public final String date;
		public final String time;
		public final String ms;
		public LMDate(String date,String time,String ms) {
			this.date = date;
			this.time = time;
			this.ms = ms;
		}
		
	}
	
}
